package yyee.llee.mmee.weather.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import yyee.llee.mmee.base_api_net.base_api_bean.bean.Air24QualityBean;
import yyee.llee.mmee.common.R;
import bh.CW;
import bh.FX;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Air7QualityAdapter extends RecyclerView.Adapter<Air7QualityAdapter.ViewHolder> {

    private List<Air24QualityBean> mList = new ArrayList<>();

    private final int minValue;

    private final int maxValue;

    public Air7QualityAdapter(List<Air24QualityBean> list) {
        this.mList.addAll(list);
        Collections.sort(list, (o1, o2) -> {
            if (o1.getQuality() > o2.getQuality())
                return 1;
            else
                return -1;
        });
        minValue = list.get(0).getQuality();
        maxValue = list.get(list.size() - 1).getQuality();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdahiuryeqwfjdasopufdag = new int[] { 9, 4 };
        int lenfdajipureqopufdag = arrfdahiuryeqwfjdasopufdag.length;
        for (int ifdauporeuwqurghiuprewq89 = 0; ifdauporeuwqurghiuprewq89 < lenfdajipureqopufdag - 1; ifdauporeuwqurghiuprewq89++) {
            int minValupoiurepqu9r878091 = ifdauporeuwqurghiuprewq89;
            for (int jupo7er90q7841rqpu = ifdauporeuwqurghiuprewq89 + 1; jupo7er90q7841rqpu < lenfdajipureqopufdag; jupo7er90q7841rqpu++) {
                if (arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] > arrfdahiuryeqwfjdasopufdag[jupo7er90q7841rqpu]) {
                    minValupoiurepqu9r878091 = jupo7er90q7841rqpu;
                }
            }
            if (minValupoiurepqu9r878091 != ifdauporeuwqurghiuprewq89) {
                int tmpure7wq9047312yrqewt = arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89];
                arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89] = arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091];
                arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] = tmpure7wq9047312yrqewt;
            }
        }
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_7_aq, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        TextView time;

        TextView quality;

        TextView status;

        CW tempChart;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            time = itemView.findViewById(R.id.tv_time);
            quality = itemView.findViewById(R.id.tv_quality);
            status = itemView.findViewById(R.id.tv_status);
            tempChart = itemView.findViewById(R.id.tempChart);
            tempChart.setMinValue(minValue);
            tempChart.setMaxValue(maxValue);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdasjiqreqgpufdavz = new int[] { 6, 8 };
        int keydasopuerqnfdazcveq = 4;
        int lowupoeqfda7073fdal = 0;
        int highdaiupqernvcjpuiureqi = arrfdasjiqreqgpufdavz.length - 1;
        int middledaiueprnvznfewqip = 0;
        if (keydasopuerqnfdazcveq < arrfdasjiqreqgpufdavz[lowupoeqfda7073fdal] || keydasopuerqnfdazcveq > arrfdasjiqreqgpufdavz[highdaiupqernvcjpuiureqi] || lowupoeqfda7073fdal > highdaiupqernvcjpuiureqi) {
            int adfajpouqregjbdipug = 1;
        } else {
            while (lowupoeqfda7073fdal <= highdaiupqernvcjpuiureqi) {
                middledaiueprnvznfewqip = (lowupoeqfda7073fdal + highdaiupqernvcjpuiureqi) / 2;
                if (arrfdasjiqreqgpufdavz[middledaiueprnvznfewqip] > keydasopuerqnfdazcveq) {
                    // 比关键字大则关键字在左区域
                    highdaiupqernvcjpuiureqi = middledaiueprnvznfewqip - 1;
                } else if (arrfdasjiqreqgpufdavz[middledaiueprnvznfewqip] < keydasopuerqnfdazcveq) {
                    // 比关键字小则关键字在右区域
                    lowupoeqfda7073fdal = middledaiueprnvznfewqip + 1;
                } else {
                }
            }
        }
        Air24QualityBean bean = mList.get(position);
        holder.quality.setText(String.valueOf(bean.getQuality()));
        holder.time.setText(FX.getWeek(bean.getTime()));
        switch(position) {
            case 0:
                holder.time.setText("今天");
                break;
            case 1:
                holder.time.setText("明天");
                break;
            case 2:
                holder.time.setText("后天");
                break;
            default:
        }
        holder.status.setText(bean.getStatus());
        holder.status.setTextColor(bean.getColor());
        holder.status.setBackgroundResource(bean.getBgResourceId());
        holder.tempChart.setPointPaintColor(bean.getColor());
        holder.tempChart.setItemPosition(position);
        // 如果是第一个
        if (position == 0) {
            holder.tempChart.setDrawLeftLine(false);
        } else // 除第一个以外
        {
            holder.tempChart.setDrawLeftLine(true);
            holder.tempChart.setLastValue(mList.get(position - 1).getQuality());
        }
        // 如果是最后一个
        if (position == mList.size() - 1) {
            holder.tempChart.setDrawRightLine(false);
        } else // 除最后一个以外
        {
            holder.tempChart.setDrawRightLine(true);
            holder.tempChart.setNextValue(mList.get(position + 1).getQuality());
        }
        if (position > 0) {
            holder.tempChart.setLeftGradient(mList.get(position - 1).getColor(), bean.getColor());
        }
        if (position < mList.size() - 1) {
            holder.tempChart.setRightGradient(bean.getColor(), mList.get(position + 1).getColor());
        }
        holder.tempChart.setCurrentValue(mList.get(position).getQuality());
    }

    @Override
    public int getItemCount() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdajpoureqofdjaiopuvz80 = new int[] { 1, 5 };
        for (int ireywq097904132784uafds = 1; ireywq097904132784uafds < arrfdajpoureqofdjaiopuvz80.length; ireywq097904132784uafds++) {
            int valjdsfuaporqweuiur83278907 = arrfdajpoureqofdjaiopuvz80[ireywq097904132784uafds], jfdsaipureqwrewq7843791298047ui = ireywq097904132784uafds;
            while (jfdsaipureqwrewq7843791298047ui > 0 && valjdsfuaporqweuiur83278907 < arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1]) {
                arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1];
                jfdsaipureqwrewq7843791298047ui--;
            }
            arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = valjdsfuaporqweuiur83278907;
        }
        return mList.size();
    }
}
